package cn.rkylin.oms.warehouse.shiporder.dao;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.warehouse.shiporder.domain.Shiporder;
import cn.rkylin.oms.warehouse.shiporder.vo.ShiporderVO;

/**
 * 发货DAO
 * 
 * @author 齐涛
 * @version 1.0
 * @created 28-9-2017 10:51:30
 */
@Repository(value = "shiporderDAO")
public class ShiporderDAOImpl implements ShiporderDAO {

    @Autowired
    protected IDataBaseFactory dao;

    /**
     * 查询发货单信息
     * 
     * @param shiporderVO
     *            发货单VO
     * @return 发货单信息
     * @throws Exception
     *             异常
     */
    public ShiporderVO getShiporderInfo(ShiporderVO shiporderVO) throws Exception {
        List<ShiporderVO> list = dao.findAllList("getShiporderInfo", shiporderVO);

        if (list != null && list.size() > 0) {
            return list.get(0);
        }

        return null;
    }

    public List<ShiporderVO> getShiporderList(ShiporderVO shiporderVO) throws Exception{
        return dao.findAllList("getShiporderInfo", shiporderVO);
    }
    /**
     * 更新发货单（枷锁）
     *
     * @param stockIn
     *            发货单bean
     * @return 更新条数
     * @throws Exception
     *             异常
     */
    public int updateShiporderLock(Shiporder shiporder) throws Exception {
        return dao.update("updateShiporderLock", shiporder);
    }
    /**
     * 更新发货单
     *
     * @param stockIn
     *            发货单bean
     * @return 更新条数
     * @throws Exception
     *             异常
     */
    public int updateShiporder(Shiporder shiporder) throws Exception {
        return dao.update("updateShiporder", shiporder);
    }

    /**
     * 系统发货单主表信息插入数据库
     *
     * @param shiporderVO
     * @return
     * @throws Exception
     */
    public int insertSelectiveShiporder(ShiporderVO shiporderVO) throws Exception {
        return dao.insert("insertSelectiveShiporder", shiporderVO);
    }

    @Override
    public int update(ShiporderVO shiporder) throws Exception {
        return dao.insert("updateByPrimaryKeySelectiveShipOrder", shiporder);
    }

    @Override
    public int selectCount(Map<String, Object> params) throws Exception {
        List resultList = dao.findList("selectShipOrderCountToday", params);
        if (resultList != null && resultList.size() > 0) {
            return (Integer)resultList.get(0);
        }
        
        return 0;
    }

    public int unGoingCount(Map<String, String> paramMap)  throws Exception{
        return dao.findOne("selectUnGoingShipOrderCount", paramMap);
    }

    public int shipedByOrderIdCount(Map<String, String> paramMap)  throws Exception{
        List resultList = dao.findList("selectShipedByOrderIdCount", paramMap);
        if (resultList != null && resultList.size() > 0) {
            return (Integer)resultList.get(0);
        }
        return 0;
    }
}
